package com.qf.controller;

import com.qf.vo.UserVo;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;

/**
 * 演示springmvc接收参数的各种方法
 */
@Controller
@RequestMapping("/param")
public class ParamController {

    //零散参数收参
    //  http://localhost:8080/param/test1?id=1&name=zzz&gender=false&birth=2018-12-12 12:20:30

    @RequestMapping("/test1")
    public String testParam1(Integer id,
                             String name,
                             Boolean gender,
                             @DateTimeFormat(pattern="yyyy-MM-dd HH:mm:ss") Date birth){
        System.out.println(id);
        System.out.println(name);
        System.out.println(gender);
        System.out.println(birth);
        return "/index.jsp";
    }

    //  实体收参
    //  http://localhost:8080/param/test2?id=1&name=zzz&gender=false&birth=2018-12-12 12:20:30

    @RequestMapping("/test2")
    public String testParam2(UserVo userVo){

        System.out.println(userVo);

        return "/user/userlist.jsp";
    }

    //  数组收参
    //http://localhost:8080/param/test3?hobby=football&hobby=basketball&hobby=volleyball
    @RequestMapping("/test3")
    public String testParam3(String[] hobby){
        for(String h:hobby){
            System.out.print(h+" ");
        }
        return "/index.jsp";
    }

    //http://localhost:8080/param/test4?hobby=football&hobby=basketball&hobby=volleyball&id=1&name=zzz&gender=false&birth=2018-12-12 12:20:30
    @RequestMapping("/test4")
    public String testParam4(UserVo userVo){
        System.out.println(userVo);
        for(String h:userVo.getHobby()){
            System.out.print(h+" ");
        }
        return "/index.jsp";
    }

}
